package net;

import java.net.ServerSocket;
import java.net.Socket;

public class NetReaderThread extends Thread {

	Socket SockCliente;
	NetComunicationLayer com;
	public String name;
	public int port;

	@Override
	public void run() {
		ServerSocket Servidor = null;
		Socket SockClient = null;
		try {
			Servidor = new ServerSocket(port);
		} catch (Exception e) {
			System.out.println("NRT : Puerto ya en uso. \n" + e.toString());
			System.exit(0);
		}
		while (true) {
			try {
				SockClient = Servidor.accept();
				try {
					System.out.print("NRT: User Conected");
					Thread userThread = new UserNetReaderThread(SockClient, com);
					userThread.run();

				} catch (Exception e) {

					System.out.println("NRT: mensaje perdido " + e.toString());
				}
			} catch (Exception e) {
				System.out.println("NRT: " + e.toString()
						+ "\n AtentionClientThread fail to receive.");
			}
		}

	}

	public NetReaderThread(int portc, NetComunicationLayer comlayer) {
		port = portc;
		com = comlayer;
	}
}